﻿<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
    <link href="../lib/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="../lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
    <link href="../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
<script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>发货条码管理</title>
</head>
<body>
    <div class="pt-5  pl-20 pr-20 pb-20">
        <form id="itemEdit" name="itemEdit" method="post" action="../ashx/spui.ashx" class="form form-horizontal">
            <input type="hidden" class="actionValue" id="editAction" name="action" value="add" />
            <input type="hidden" id="id" name="id" />
            <input type="hidden" id="fgid" name="fgid" value="" />
            <input type="hidden" id="tablename" name="tablename" value="" />
            <input type="hidden" id="tablemidname" name="tablemidname" value="" />
            <!-- <input type="hidden" id="fstate" name="fstate" value="草稿" />-->
            <input type="hidden" id="dataneedtouser" name="dataneedtouser" value="1" /><!--是否要包含通用数据必归属处理-->

            <ul>

                <li class="item">
                    <h4>条码信息<b></b></h4>
                    <div class="panel panel-primary">
                        <div class="panel-body">
                            <div class="row cl layui-form">
                                <label class="form-label col-1">地块信息：</label>
                                <div class="formControls col-3  layui-form">
                                    <select name="finfoid" id='selectdcinfos' lay-filter="selectdcinfos" lay-search="">
                                        <option value="">直接选择或搜索选择</option>
                                    </select>
                                </div>
                                <label class="form-label col-1">品种：</label>
                                <div class="formControls col-3  layui-form">
                                    <select name="selectpjinfo" id='selectpjinfo' lay-filter="selectpjinfo" lay-search="">
                                        <option value="">直接选择或搜索选择</option>
                                    </select>
                                </div>
                                <div class="formControls col-2">

                                    <select class="select" size="1" name="selectproductstate" id="selectproductstate">
                                        <option value="原料">原料</option>
                                        <option value="包装品">包装品</option>
                                    </select>

                                </div>

                            </div>
                            <div class="row cl">
                                <div class="formControls col-7" id="findfdiv">
                                    <label class="form-label col-2">采收时间：</label>
                                    <div class="formControls col-3">
                                        <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" name="findgetdata" id="findgetdata" class="input-text Wdate" />
                                    </div>

                                    <label class="form-label col-2">发货时间：</label>
                                    <div class="formControls col-3" id="">
                                        <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" name="findsetdate" id="findsetdate" class="input-text Wdate" />
                                        <input type="text" id="findcsgetpc_d" name="findcsgetpc_d" value="" style="display: none;" />
                                    </div>
                                </div>
                                <label class="form-label col-1">条码序号：</label>
                                <div class="formControls col-2">
                                    <input type="text" class="input-text" placeholder="条码序号" name="selectcodeindex" id="selectcodeindex" value="1" />
                                </div>
                                <div class="formControls col-2">

                                    <button onclick="addOrderSpListInfo();" class="btn btn-danger radius" type="button">添加</button>
                                    <button onclick="loadstoreinfo();" class="btn btn-danger radius" type="button">查询</button>

                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="panel panel-success">
                        <div class="panel-header">出库列表</div>
                        <div id="tableArea">
                            <table class="table table-border table-bordered table-striped table-hover" id="tablelist" style="width: 100%;">
                                <thead>
                                    <tr class="text-c">
                                        <th width="30"><a id="hcmtable_sall" onclick="hcmtable_sall();" href="javascript:;" title="全选反选"><i class="Hui-iconfont">&#xe608;全</i></a></th>

                                        <th>基本信息</th>
                                        <th>类别</th>
                                        <th>序号</th>
                                        <th>采收日期</th>
                                        <th>发货日期</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </li>
            </ul>


            <div class="row cl">
                <div class="col-6 col-offset-4">
                    <!--  <button onclick="changeshowtype();" class="btn btn-danger radius" type="button">切换显示</button>&nbsp;&nbsp;&nbsp;&nbsp;-->
                    <button class="btn btn-primary radius" type="submit" id="btsub1">保存</button>&nbsp;&nbsp;
				<button class="btn btn-secondary radius" type="button" id="btn_reset">重置</button>&nbsp;&nbsp;
                    <button onclick="layer_close();" class="btn btn-default radius" type="button">返回</button>
                </div>
            </div>

        </form>
    </div>
    <script src="../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../lib/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="../lib/Validform/5.3.2/Validform.js"></script>
    <script type="text/javascript" src="../lib/layer/1.9.3/layer.js"></script>
    <script src="../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/hcui.js"></script>
    <script type="text/javascript" src="../js/hcui_au.js"></script>
    <script type="text/javascript" src="../js/hcrainwf.js"></script>
    <script type="text/javascript" src="../lib/My97DatePicker/WdatePicker.js"></script>

    <script type="text/javascript" src="../lib/datatables/1.10.0/jtable.js"></script>
    <script type="text/javascript" src="../js/hcui_list.js"></script>

    <script type="text/javascript">
        var uiform = null;
        var divshowtype = 1;
        if (getUrlParam("urlgettime")) {
            $("#findgetdata").val(getUrlParam("urlgettime"));
        } else            $("#findgetdata").val(new Date().Format("yyyy-MM-dd"));        if (getUrlParam("urlsettime")) {
            $("#findsetdate").val(getUrlParam("urlsettime"));
        } else            $("#urlsettime").val(new Date().Format("yyyy-MM-dd"));
        //本页面 
        spsetBaseNoBt("task_send_info_list", "id", "task_send_info_list as T", "*", "#tablelist", "task_send_info_list", "出入库管理", "task_send_info_list");



        //加载处理
        function loadin() {
            layui.use(['form'], function () {
                uiform = layui.form();

                if (getUrlParam("action") == "add") {
                    $("#fgid").val(NewGuid());
                    table_reset();
                }

                //地块信息
                hcdoselbyPost("id,concat(fv1,'-',fv8) as name,nv1,fv1,fv8,fv10,fv7,fv9,fv6,fv4,fv5", "yw_baseinfo", "type=2 and maintype=2 and databranchid=" + HCUser.HCUorg, "", "", "id",
                       function (data) {
                           SetSelectWithArrayIdName("#selectdcinfos", data);
                           uiform.render('select');
                       });
                hcdoselbyPost("id,fv1 as name", "yw_baseinfo", "type=1 and maintype=1", "", "", "id", function (data) {
                    SetSelectWithArrayIdName("#selectpjinfo", data);
                    if (uiform) uiform.render('');
                });
                //uiform.on('select(testselect)', function (data) {//选择交接人处理
                //    $('#finoutuserid').val(data.value);
                //    $('#finoutusername').val($("#inoutusernamesel").find("option:selected").text());
                //});

                //uiform.on('select(testselectfl)', function (sdata) {//分类选择处理--加载分类明细
                //    hcdoselbyPost("id,concat(productno) as name,unit", "herp_product", "producttype='" + sdata.value + "' and databranchid='" + HCUser.HCUorg + "'", "", "", "id", function (data) {
                //        SetSelectWithArrayIdName("#selherp_product", data);
                //        inoutproductObj = data;
                //        uiform.render('select');
                //        $("#sellistid").val("");
                //    });

                //});

                //uiform.on('select(selherp_product)', function (sdata) {//物品选择处理--加载 库存明细
                //    if ($("#fstoreid").val() == "") {
                //        layer.msg('仓库不能为空', { icon: 1 });
                //        return;
                //    }
                //    hcdoselbyPost("id,concat('批次:',spbasepc,'-厂家:',spbasecj,'-单价：',price,'-库存：',count-hasout,'-生产日期:',case when spbasecdate  is null  then '' else DATE_FORMAT(spbasecdate,'%Y-%m-%d') END ) as name,spbasepc,spbasecj,spbasecdate,unit,price,spbasezj,count-hasout as countnew", "herp_inoutorderlist", "databranchid='" + HCUser.HCUorg + "'    and spid=" + sdata.value + " and storeid =" + $("#fstoreid").val() + " and datastate='入库' and count-hasout>0", "", "", "dataaddtime asc", function (data) {
                //        SetSelectWithArrayIdName("#selherp_productpc", data);
                //        inoutproductObj2 = data;
                //        uiform.render('select');
                //        $("#sellistid").val("");
                //    });

                //});
                //uiform.on('select(selherp_productpc)', function (data) {
                //    $('#selprice').val(hcgetJsonObjById(inoutproductObj2, data.value).price);
                //    $('#selspbasecdate').val(hcgetJsonObjById(inoutproductObj2, data.value).spbasecdate);
                //    $('#selspbasecj').val(hcgetJsonObjById(inoutproductObj2, data.value).spbasecj);
                //    $('#selspbasezj').val(hcgetJsonObjById(inoutproductObj2, data.value).spbasezj);
                //    $('#selunit').val(hcgetJsonObjById(inoutproductObj2, data.value).unit);
                //    $('#sellistid').val(hcgetJsonObjById(inoutproductObj2, data.value).id);
                //    $('#sellistidkc').val(hcgetJsonObjById(inoutproductObj2, data.value).countnew);
                //    $('#selspbasepc').val(hcgetJsonObjById(inoutproductObj2, data.value).spbasepc);

                //});

                //下拉加载-仓库
                //hcdoselbyPost("id,name", "herp_storehouse", "databranchid='" + HCUser.HCUorg + "'", "", "", "id", function (data) {
                //    SetSelectWithArrayIdName("#fstoreid", data);
                //    $('#fstoreid option:eq(1)').attr('selected', 'selected');//选择第二(1)个
                //});

                ////下拉加载 --物品主分类
                //hcdoselbyPost("dictdata_code as id,dictdata_name as name", "dictionarydata", "dict_code='ErpProductMtype'", "", "", "orderindex",
                //       function (data) {
                //           SetSelectWithArrayIdName("#selfproducttype", data);
                //           uiform.render('select');
                //       });
                ////下拉加载 --人员
                //hcdoselbyPost("empid  as id,concat(depname,'-',empname) as name,empname as username,mobile as  tel,depname as address", "view_user", "branchid='" + HCUser.HCUorg + "'", "", "", "id",
                //    function (data) {
                //        SetSelectWithArrayIdName("#inoutusernamesel", data);

                //        uiform.render('select');
                //    });
                ////进行中的任务-下拉

                //hcdoselbyPost("id,concat('编号:',taskno,'-',infofv1,'-',tasksctypename,'-',case when taskusername  is null  then '' else  taskusername END  ) as name", "view进行中的任务", "databranchid='" + HCUser.HCUorg + "'", "", "", "id",
                //    function (data) {
                //        SetSelectWithArrayIdName("#seltaskinfo", data);
                //        uiform.render('select');
                //    });
            });




        }
        function loadstoreinfo() {

            //alert($("#findsetdate").val());
            if ($("#findgetdata").val() == "" || $("#findsetdate").val() == "") {
                layer.msg('日期不能这空', { icon: 2 });
                return;
            }



            if ($('#selectdcinfos').val() == "" || $('#selectpjinfo').val() == "") {
                $("#findcsgetpc_d").val("");
            }
            else {
                var csgetpc = HCUser.HCUorg
                + "_" + $('#selectdcinfos').val()
                + "_" + $('#selectpjinfo').val()
                + "_" + $('#findgetdata').val();


                $("#findcsgetpc_d").val(csgetpc);
            }
            hcmtable.ajax.reload();
        }

        function table_reset() {
            hcmtable = $("#tablelist").DataTable({
                "serverSide": true,//服务端处理分页 无法使用当前查找
                "bFilter": false,  //是否使用内置的过滤功能
                "bLengthChange": false, //改变每页显示数据数量
                "ajax": {
                    "type": "POST",
                    "url": sposelUrl("task_send_info_list", "*", " and databranchid=" + HCUser.HCUorg) + "&sporderby=id",
                    "data": function (d) {
                        $("#findfdiv").find("input[type='text']").each(function () {
                            d[this.id] = $(this).val();
                        });
                        //$("#findfdiv").find("select").each(function () {
                        //    d[this.id] = $(this).val();
                        //});
                    }

                },
                aLengthMenu: [100],
                "columns": [
                      { "data": "rowhcindex" },
                      { "data": "codeinfo" }, { "data": "productstate" }, { "data": "codeindex" },
        
        { "data": "getdata" },
        { "data": "setdate" },
      { "data": "id" }

                ],
                "columnDefs": [

                    {
                        "targets": [6],
                        "render": function (data, type, row) {
                            if (loadbackdata.state == '完成')
                            { return "<a style=\"text-decoration:none\" class=\"ml-5\" onClick=\"toolUpdateById(" + data + ", '编辑出库信息', 'StoreInOutList-ae.html?action=edit&id=' + " + data + ")\" href=\"javascript:;\" title=\"编辑\"><i class=\"Hui-iconfont\">&#xe6df;编辑</i></a> "; }
                            else
                                return "<a style=\"text-decoration:none\" class=\"ml-5\" onclick=\"toolDelete('" + data + "','task_send_info_list','id')\"     href=\"javascript:;\" title=\"删除\"><i class=\"Hui-iconfont\">&#xe6e2;删除</i></a>";
                        }
                    },

                {
                    "orderable": false,
                    "targets": [0, 1, 2, 3]
                }
                ]
            });
        }



        var oldstate = "待出库";
        var loadbackdata = [];
        //加载完成后,加载明细列表
        function loadback(data) {
            table_reset();
            loadbackdata = data;
            oldstate = loadbackdata.state;
            //if (loadbackdata.state == '完成')//已完成，不能修必出入库状态
            //{
            //    $("#btsub1").hide();
            //}
            if (loadbackdata.state == '完成')//已完成，不能修必出入库状态
            {
                $("#fstate").attr("disabled", "disabled");
            }
            if (getUrlParam("action") == "edit") {
                $("#fstoreid").attr("disabled", "disabled");
            }

        }
        //添加明细
        function addOrderSpListInfo() {
            if ($("#selectdcinfos").val() == "") {
                layer.msg('地块不能为空', { icon: 2 });
                return;
            }
            if ($("#selectpjinfo").val() == "") {
                layer.msg('品种不能为空', { icon: 2 });
                return;
            }
            //alert($("#findsetdate").val());
            if ($("#findgetdata").val() == "" || $("#findsetdate").val() == "") {
                layer.msg('日期不能这空', { icon: 2 });
                return;
            }
            if ($("#selectcodeindex").val() == "") {
                layer.msg('序号不能为空', { icon: 2 });
                return;
            }


            var csgetpc = HCUser.HCUorg
               + "_" + $('#selectdcinfos').val()
               + "_" + $('#selectpjinfo').val()
               + "_" + $('#findgetdata').val();
            var codepc = csgetpc + "_150" + "_" + $("#selectproductstate").val() + "_" + $("#selectcodeindex").val();
            var codeinfo = HCUser.HCUorg
               + "_" + $('#selectdcinfos').find("option:selected").text()
               + "_" + $('#selectpjinfo').find("option:selected").text()
               + "_" + $('#findgetdata').val();
            $("#findcsgetpc_d").val(csgetpc);

            // $("#fstoreid").attr("disabled", "disabled");
            var addinfo = "csgetpc%" + csgetpc
                + "$settocenterid%150"
                + "$productstate%" + $("#selectproductstate").val()
                + "$setdate%" + $("#findsetdate").val()
                + "$getdata%" + $("#findgetdata").val()
                + "$codeindex%" + $("#selectcodeindex").val()
                + "$codeinfo%" + codeinfo
                 + "$databranchid%" + HCUser.HCUorg
                + "$codepc%" + codepc;
            hcdoadd201702("task_send_info_list", addinfo, 0, "", "fcodepc,fsetdate#当前记录已在出库列表，可以删除再添加!", function (info) {
                console.log(info);
                if (info == "ok") hcmtable.ajax.reload();
                else {
                    layer.msg(info, { icon: 2 });
                }


            });
        }
        //提交数据后,回调
        function subback(data) {
            if (data.status == "y") {
                var showmessage = "处理成功";
                if (loadbackdata.state != '完成' && $("#fstate").val() == "提交出库") {               //分析是否要同步库存
                    //提交同步数据
                    $.ajax({
                        type: "get",
                        url: spPageUrl,
                        data: {
                            "action": "doProc",
                            "procName": "doProcOutorderOK",
                            "hcporderguid": $("#fgid").val()
                        },
                        timeout: 30,
                        async: false,
                        cache: false,
                        error: function () {
                            alert("error");
                        },
                        success: function (re) {
                            var data = JSON.parse(re);
                            if (data.message == JsonResult.Success) {
                                showmessage = data.data;
                                hcapigetNoError("../api/Task/GetStoreTask", {}, function (backdata) {
                                });
                            }
                            else {
                                layer.alert(data.data, { icon: 2 });
                                return;
                            }
                        }
                    });

                }
                if (getUrlParam("action") == "add") {
                    if ($("#fgid")) { $("#fgid").val(NewGuid()); }
                }

                layer.confirm(showmessage, {
                    btn: ['确认'] //按钮
                }, function (index) {
                    layer_close();
                    //layer.msg('继续添加', { icon: 1 });
                    //$("#btn_reset").click();
                    //table_reset();
                }, function (index) {
                    layer_close();
                });


                //layer.alert(data.info, { icon: 1 });

            }
            else {
                layer.alert(data.info, { icon: 2 });
            }
        }
        //重写  提交前数据处理
        function hcrBeforeSub() {
            $("#fstoreid").removeAttr("disabled");
        }
        function storechange() {
            SetSelectWithArrayIdName("#selherp_productpc", []);
            uiform.render('select');
        }
    </script>
</body>
</html>
